package com.example.a28796.beautiful.zhangyuqiadapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by admin on 2016/8/30.
 */
public class BeautyPagerAdapter extends PagerAdapter {
    private List<ImageView> imageViews;

    public BeautyPagerAdapter(List<ImageView> imageViews) {
        this.imageViews = imageViews;
    }

    @Override
    public int getCount() {
        if (imageViews.size() == 0) {
            return 0;
        } else {
            return Integer.MAX_VALUE;
        }

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        if (imageViews.size() == 0) {
            return 0;
        } else {
            int newposition = position % imageViews.size();
            container.addView(imageViews.get(newposition));
            return imageViews.get(newposition);
        }

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        if (imageViews.size() == 0) {
            container.removeView(imageViews.get(position));
        } else {
            int newposition = position % imageViews.size();
            container.removeView(imageViews.get(newposition));
        }

    }
}
